package cn.com.longfuinfo.wx.common;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

/**
 * 系统常量获取<br/>
 * 从数据库t_sys_config表获取
 */
public class SysConfig {
	private static final String LEVEL2_LINE_CODE = "S0001";
	private static final String sppoint = "S0002";
	private static final String jypoint = "S0003";
	private static final String jkpoint = "S0004";

 
	/**
	 * 获取普通用户升级为会员时要满足的消费金额线
	 */
	public static double getLevel2Line() throws Exception{
		return (double)getFinalValue(LEVEL2_LINE_CODE);
	}
	/**
	 * 商品积分比例
	 */
	public static double getSppoint()throws Exception{
		return (double)getFinalValue(sppoint);
	}
	/**
	 * 教育积分比例
	 */
	public static double getJypoint()throws Exception{
		return (double)getFinalValue(jypoint);
	}
	/**
	 * 健康积分比例
	 */
	public static double getJkpoint()throws Exception{
		return (double)getFinalValue(jkpoint);
	}
	/**
	 * 根据常量字符串获取对应的常量值
	 *@param code 系统常量表中存在的code
	 * @throws Exception 
	 */
	public static Object getFinalValue(String code) throws Exception{
		Record config = Db.findFirst("SELECT value FROM t_sys_config WHERE code=?",code);
		if(config!=null){
			return Double.valueOf(config.getStr("value"));
		}
		throw new Exception("系统配置常量（代码："+code+"）对应的值找不到!");
	}
	
}
